.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved.  The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.\"	@(#)setjmp.3	6.2 (Berkeley) 1/9/86
.\"
.TH SETJMP 3 "January 9, 1986"
.UC 4
.SH NAME
setjmp, longjmp \- non-local goto
.SH SYNOPSIS
.nf
.B #include <setjmp.h>
.PP
.B setjmp(env)
.B jmp_buf env;
.PP
.B longjmp(env, val)
.B jmp_buf env;
.PP
.B _setjmp(env)
.B jmp_buf env;
.PP
.B _longjmp(env, val)
.B jmp_buf env;
.fi
.SH DESCRIPTION
These routines are useful for dealing with errors 
and interrupts encountered in
a low-level subroutine of a program.
.PP
.I Setjmp 
saves its stack environment in
.I env
for later use by
.I longjmp.
It returns value 0.
.PP
.I Longjmp
restores the environment saved by the last call of
.IR setjmp .
It then returns in such a way that execution
continues as if the call of 
.I setjmp
had just returned the value
.I val
to the function that invoked
.I setjmp,
which must not itself have returned in the interim.
All accessible data have values as of the time
.I longjmp
was called.
.PP
.I Setjmp
and
.I longjmp
save and restore the signal mask
.IR sigmask (2),
while
.I _setjmp
and
.I _longjmp
manipulate only the C stack and registers.
.SH ERRORS
.PP
If the contents of the
.B jmp_buf
are corrupted, or correspond to an environment that has already returned,
.I longjmp
calls the routine 
.IR longjmperror .
If
.I longjmperror
returns the program is aborted.
The default version of 
.I longjmperror
prints the message ``longjmp botch'' to standard error and returns.
User programs wishing to exit more gracefully can write their own
versions of 
.IR longjmperror .
.SH "SEE ALSO"
sigvec(2), sigstack(2), signal(3)
.SH "NOTES  (PDP-11)"
On the PDP-11, \fIlongjmperror\fP is called as \fI_ljerr\fP.  This
difference stems from the limited name size of the PDP-11 that requires all
external names to be unique within the first seven characters.  However,
<\fIsetjmp.h\fP> automatically translates \fIlongjmperror\fP to \fIljerror\fP
and should be included before any definition \fIlongjmperror\fP.
.PP
The PDP-11 implementation also contains a subtle bug that occurs when a
routine containing a \fIsetjmp\fP has \fIregister\fP variables.  The bug
sometimes causes those variables to be given invalid values when a longjmp
is made back to the routine.  \fIRegister\fP variables should therefore be
avoided in routines containing \fIsetjmps\fP.
.PP
And finally, _longjmp may sometimes die fatally.  Sorry.
